class ReceivingApiResponse {
  final int code;
  final Receivingobj data;
  final String msg;

  ReceivingApiResponse({
    required this.code,
    required this.data,
    required this.msg,
  });

  factory ReceivingApiResponse.fromJson(Map<String, dynamic> json) {
    return ReceivingApiResponse(
      code: json['code'] as int,
      data: json['data'] as Receivingobj,
      msg: json['msg'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'data': data,
      'msg': msg,
    };
  }
}

class Receivingobj {
  final int id;
  final int warehouse;
  final int order;
  final OrderInfo orderInfo;
  final String shipmentCode;
  final String status;
  final String packType;
  final String checkinTime;
  final int totalLpns;
  final int received;
  final List<ReceivedShipmentLine>? receivedShipmentLines;
  final List<ReceivingShipmentLine>? receivingShipmentLines;

  Receivingobj({
    required this.id,
    required this.warehouse,
    required this.order,
    required this.orderInfo,
    required this.shipmentCode,
    required this.status,
    required this.packType,
    required this.checkinTime,
    required this.totalLpns,
    required this.received,
    required this.receivedShipmentLines,
    this.receivingShipmentLines,
  });

  factory Receivingobj.fromJson(Map<String, dynamic> json) {
    print('json--$json');
    return Receivingobj(
      id: json['id'] as int,
      warehouse: json['warehouse'] as int,
      order: json['order'] as int,
      orderInfo: OrderInfo.fromJson(json['order_info']),
      shipmentCode: json['shipment_code']??'',
      status: json['status']??'',
      packType: json['pack_type']??'',
      checkinTime: json['checkin_time']??'',
      totalLpns: json['total_lpns'] as int,
      received: json['received'] as int,
      receivedShipmentLines: (json['received_shipment_lines'] as List)
          .map((e) => ReceivedShipmentLine.fromJson(e))
          .toList(),
      receivingShipmentLines: (json['receiving_shipment_lines'] as List)
          .map((e) => ReceivingShipmentLine.fromJson(e))
          .toList(),
    );
  }

  // Map<String, dynamic> toJson() {
  //   return {
  //     'id': id,
  //     'warehouse': warehouse,
  //     'order': order,
  //     'order_info': orderInfo.toJson(),
  //     'shipment_code': shipmentCode,
  //     'status': status,
  //     'checkin_time': checkinTime,
  //     'total_lpns': totalLpns,
  //     'received': received,
  //     'received_shipment_lines': receivedShipmentLines?.map((e) => e.toJson()).toList()??[],
  //     'receiving_shipment_lines': receivingShipmentLines?.map((e) => e.toJson()).toList()??[],
  //   };
  // }
}

class OrderInfo {
  final int id;
  final String orderNumber;
  final String orderType;

  OrderInfo({
    required this.id,
    required this.orderNumber,
    required this.orderType,
  });

  factory OrderInfo.fromJson(Map<String, dynamic> json) {
    return OrderInfo(
      id: json['id'] as int,
      orderNumber: json['order_number'] ??'',
      orderType: json['order_type'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'order_number': orderNumber,
      'order_type': orderType,
    };
  }
}

class ReceivedShipmentLine {
  final int id;
  final String lineNumber;
  final String lpnNumber;
  final String itemNumber;
  final String packKey;
  final int orderPackQuantity;
  final String packType;
  final int quantity;
  final String status;
  final String itemName;
  final String shortDescription;

  ReceivedShipmentLine({
    required this.id,
    required this.lineNumber,
    required this.lpnNumber,
    required this.itemNumber,
    required this.packKey,
    required this.orderPackQuantity,
    required this.packType,
    required this.quantity,
    required this.status,
    required this.itemName,
    required this.shortDescription,
  });

  factory ReceivedShipmentLine.fromJson(Map<String, dynamic> json) {
    return ReceivedShipmentLine(
      id: json['id'] as int,
      lineNumber: json['line_number'] ??'',
      lpnNumber: json['lpn_number'] ??'',
      itemNumber: json['item_number'] ??'',
      packKey: json['pack_key'] ??'',
      orderPackQuantity: json['order_pack_quantity'] as int,
      packType: json['pack_type'] ??'',
      quantity: json['quantity'] as int,
      status: json['status'] ??'',
      itemName: json['item_name'] ??'',
      shortDescription: json['short_description'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'line_number': lineNumber,
      'lpn_number': lpnNumber,
      'item_number': itemNumber,
      'pack_key': packKey,
      'order_pack_quantity': orderPackQuantity,
      'pack_type': packType,
      'quantity': quantity,
      'status': status,
      'item_name': itemName,
      'short_description': shortDescription,
    };
  }
}
class ReceivingShipmentLine {
  final int id;
  final String lineNumber;
  final String lpnNumber;
  final String itemNumber;
  final String packKey;
  final int orderPackQuantity;
  final String packType;
  final int quantity;
  final String status;
  final String itemName;
  final String shortDescription;
  final String internalItemNumber;

  ReceivingShipmentLine({
    required this.id,
    required this.lineNumber,
    required this.lpnNumber,
    required this.itemNumber,
    required this.packKey,
    required this.orderPackQuantity,
    required this.packType,
    required this.quantity,
    required this.status,
    required this.itemName,
    required this.shortDescription,
    required this.internalItemNumber,
  });

  factory ReceivingShipmentLine.fromJson(Map<String, dynamic> json) {
    return ReceivingShipmentLine(
      id: json['id'] as int,
      lineNumber: json['line_number'] ??'',
      lpnNumber: json['lpn_number']??'',
      itemNumber: json['item_number'] ??'',
      packKey: json['pack_key'] ??'',
      orderPackQuantity: json['order_pack_quantity'] as int,
      packType: json['pack_type'] ??'',
      quantity: json['quantity'] as int,
      status: json['status'] ??'',
      itemName: json['item_name'] ??'',
      shortDescription: json['short_description'] ??'',
      internalItemNumber: json['internal_item_number'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'line_number': lineNumber,
      'lpn_number': lpnNumber,
      'item_number': itemNumber,
      'pack_key': packKey,
      'order_pack_quantity': orderPackQuantity,
      'pack_type': packType,
      'quantity': quantity,
      'status': status,
      'item_name': itemName,
      'short_description': shortDescription,
      'internal_item_number': internalItemNumber,
    };
  }
}
